
import 'package:flutter/material.dart';

///
/// notification_listener_demo.dart
///
///

void main() => runApp(const NotificationListenerDemoWidget());


class NotificationListenerDemoWidget extends StatelessWidget {
  const NotificationListenerDemoWidget({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    final result = MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('notification_listener_demo')),
        // ScrollNotification
        body: NotificationListener<ScrollUpdateNotification> (
          onNotification: (scrollNotify){

            // === 这下面是ch13，陈航老师的示例，但是现在不管用了，只有 start 会执行
            // if (scrollNotify is ScrollNotification) {
            //   print('Scroll Start');
            // } else if (scrollNotify is ScrollUpdateNotification) {
            //   print('Scroll Update');
            // } else if (scrollNotify is ScrollEndNotification) {
            //   print('Scroll End');
            // }
            // === https://juejin.cn/post/6991290527433900063
            // 下面这个打印是从上面文章中摘抄下来的代码
            print('==dragDetail: ${scrollNotify.dragDetails}; ==pixels: ${scrollNotify.metrics.pixels}');
            // Return true to cancel the notification bubbling.
            // Return false to allow the notification to continue to be dispatched to further ancestors.
            return false;
          },
          child: ListView.builder(
            itemCount: 30,
            itemBuilder: (context, index) => ListTile(title: Text('Index : $index'),),
          ),
        ),
      ),
    );
    return result;
  }
}




